package com.heyqing.topic.IsPerfectSquare_0367;

/**
 * ClassName:IsPerfectSquare
 * Package:com.heyqing.topic.IsPerfectSquare_0367
 * Description:
 *
 * @Date:2024/9/27
 * @Author:Heyqing
 */
public class IsPerfectSquare {
    public boolean isPerfectSquare(int num) {
        if (num == 1) return true;
        int end = num / 2, start = 2;
        while (start <= end) {
            int mid = start + (end - start) / 2;
            if (mid > 46340) mid = 46340;
            int square = mid * mid;
            if (start == mid) return square == num;
            if (square == num) return true;
            else if (square > num) end = mid;
            else start = mid;
        }
        return false;
    }
}
